package it.poste.il.compensatore.dao.impl;

import it.poste.il.compensatore.dao.MessageStatusDao;
import it.poste.il.compensatore.entity.Message;
import it.poste.il.compensatore.entity.MessageStatus;
import it.poste.il.compensatore.entity.User;

import java.util.List;

import javax.persistence.NoResultException;

import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

public class MessageStatusDaoImpl extends BaseEntityDaoImpl<MessageStatus> implements MessageStatusDao {
	@Autowired(required=true)
	private SessionFactory sessionFactory;
	
	public MessageStatusDaoImpl() {
        super(MessageStatus.class, "MessageStatus");
    }

    public List<MessageStatus> loadByFilter(MessageStatus entityFilter) {
        throw new UnsupportedOperationException();
    }

    public MessageStatus loadByExample(MessageStatus entity) {
        throw new UnsupportedOperationException();
    }
    
	@Transactional()
	public MessageStatus findById(String id) {
		this.sessionFactory.getCurrentSession().beginTransaction();
		return (MessageStatus) this.sessionFactory.getCurrentSession().createQuery(
		"from MessageStatus messageStatus where messageStatus.id=?").setParameter(0, id)
		.uniqueResult();
	}
    
	@Transactional
	public String selectDescription(MessageStatus msgSts) {
		try {
		      return (String) getEntityManager().createNamedQuery("SELECT msgSts.description FROM MessagesStatus msgSts " +
	              "WHERE msgSts.id = :id").
	              setParameter("id", msgSts.getId()).
	              getSingleResult();
		} catch (NoResultException e) {
		      return null;
		}
	}
}
